HAL GPIO migration: List of applicable concepts

This section provides information about the HAL GPIO applicable architecture concepts.

Concepts for GPIO

Concept

Description

HAL implementation with LL inline functions

HAL GPIO APIs now rely on LL APIs rather than performing direct register access.

Define statements and enumerations redirected to LL equivalents

HAL GPIO define statements and enumerations are based on LL define statements.

Removal of hardware-related macros in HAL2

All hardware macros have been removed from the HAL GPIO driver, and equivalent services are ensured through the LL APIs.

Revised and optimized HAL API status returns

The HAL GPIO functions were updated to return:

  • HAL_INVALID_PARAM: in case of a NULL p_config structure pointer.

  • HAL_ERROR: in case of an error.

  • HAL_OK: in case of a successfully completed operation.

Replaced TypeDef suffix with _t in type names

All TypeDef parts of the HAL GPIO driver have been removed and replaced by _t.

Replaced nonmodifiable pointers with const keywords

Const keywords have been added to non-modifiable pointers to ensure that either the pointer itself or the data it points to cannot be modified. This enhances code safety and readability, prevents unintended modifications, and renders code more robust and maintainable.

Assertion implementation and usage in HAL1

There is no state machine in the HAL GPIO. The parameters are checked using ASSERT_DBG_PARAM macro.

Merge HAL extension files with common ones and remove the EX prefix from APIs.

Only one HAL GPIO header file remains and all macros, define statements, and functions from hal_gpio_ex.h have been moved to hal_gpio.h.

Add HAL_GPIO_WriteMultipleStatePin, allowing setting and clearing several pins of a dedicated port with a single register access.

Adding HAL_GPIO_WriteMultipleStatePin : write in one shot the BSRR register setting and restting several pins in the same cycle.

Update the GPIO init structure and function to move Pins as a standalone parameter of the function.

The field Pins is no more part of the hal_gpio_config_t, instead it is passed as an argument to the HAL_GPIO_Init.

Remove EXTI Intrinsic Management in System HAL Drivers; Let Users Rely on EXTI HAL Driver.

No more IT/EVT modes in the GPIO, keep only INPUT/OUTPUT/ALTERNATE/ANALOG in the enumeration hal_gpio_mode_t and PUSHPULL/OPENDRAIN in the enumeration hal_gpio_output_t.

The GPIO_EXTI callback and the HAL_GPIO_EXTI_IRQHandler function have been removed.

Replace Finite Parameter Defines (Including PPP Instances) with Enum Types at HAL Levels.

Finite parameters (including GPIO instances) have been converted into enumerated types (enums) at HAL level. This improves code readability, maintainability, and type safety.

Add HAL_PPP Prefix to All HAL Peripheral APIs (Defines, Macros, Types, and Functions).

All HAL GPIO functions start with HAL_GPIO.All HAL GPIO enumerations and structures start with hal_gpio.

Other HAL GPIO changes

Concept

Consideration

Add alias defines for peripherals to simplify alternate function identification; these defines are derived from the dedicated AF enumeration

In HAL1, these defines were available in hal_gpio_ex.h; in HAL2, they have been moved to hal_gpio.h. These defines are now based on the dedicated AF enumeration.

Split mode and output type

Provide a dedicated parameter for the mode (IN, OUT, AF, ANALOG) and a separate parameter for the output type (push-pull or open-drain). The rationale is to align with the LL, which offers separate APIs for mode and output type, and to allow the user to select the output type independently.